package com.woniuxy02;

import java.util.Scanner;

/**
 * @author 作者
 * @create 2025-08-28 17:11
 */
public class Test09 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int personFist, computerFist;
        int personWin=0,computerWin=0,count=0;
        String personShow="", computerShow="",answer="";
        System.out.println("是否开始游戏y/n");
        answer = sc.next();
        while ("y".equals(answer)) {
            count++;
            //-------------------玩家出拳-------------------
            System.out.println("玩家出拳1剪刀,2石头,3布");
            personFist = sc.nextInt();
            //出拳输入不是1,2,3继续输入
            //输入正确  personFist==1 || personFist==2 || personFist==3
            while (!(personFist == 1 || personFist == 2 || personFist == 3)) {
                System.out.println("出拳错误，1剪刀,2石头,3布");
                personFist = sc.nextInt();
            }
            //-------------------显示玩家出拳-------------------
            switch (personFist) {
                case 1:
                    personShow = "剪刀";
                    break;
                case 2:
                    personShow = "石头";
                    break;
                case 3:
                    personShow = "布";
                    break;
            }
            System.out.println("玩家出拳:" + personShow);
            //-------------------电脑出拳-------------------
            computerFist = (int) (Math.random() * 100) % 3 + 1;
            //-------------------显示电脑出拳-------------------
            switch (computerFist) {
                case 1:
                    computerShow = "剪刀";
                    break;
                case 2:
                    computerShow = "石头";
                    break;
                case 3:
                    computerShow = "布";
                    break;
            }
            System.out.println("电脑出拳:" + computerShow);
            //-------------------判断本局胜负-------------------
            if((personFist==1&&computerFist==3)||(personFist==2&&computerFist==1)||(personFist==3&&computerFist==1)){
                personWin++;
                System.out.println("本局玩家获胜");
            }else if(personFist==computerFist){
                System.out.println("本局平局");
            }else{
                computerWin++;
                System.out.println("本局电脑获胜");
            }
            System.out.println("是否继续下一局y/n");
            answer = sc.next();
        }
        //-------------------统计最终胜负-------------------
        if(count>0){
            System.out.println("对战总局数:"+count);
            System.out.println("玩家获胜局数:"+personWin);
            System.out.println("电脑获胜局数:"+computerWin);
            if(personWin>computerWin){
                System.out.println("最终玩家获胜");
            }else if(personWin==computerWin){
                System.out.println("最终平局");
            }else{
                System.out.println("最终电脑获胜");
            }
        }
    }
}
